import http from '@/api/request';

/**
 * 微信小程序授权
 * @param loginCode 登录动态令牌
 * @param phoneCode 手机动态令牌
 * @param inviteCode 邀请码
 * @returns
 */
export const wxOauth = (loginCode: string, phoneCode: string, inviteCode: string) => {
  return http.request({
    method: 'POST',
    url: '/app/oauth/wx',
    data: { loginCode: loginCode, phoneCode: phoneCode, inviteCode: inviteCode },
  });
};

/**
 * h5密码授权
 * @param phone 手机号
 * @param password 密码
 * @returns
 */
export const h5OauthByPassword = (phone: string, password: string, loginCode = '') => {
  return http.request({
    method: 'POST',
    url: '/app/oauth/h5/password',
    data: { phone: phone, password: password, loginCode: loginCode },
  });
};

/**
 * h5验证码授权
 * @param phone 手机号
 * @param code 密码
 * @returns
 */
export const h5OauthByCode = (phone: string, code: string, loginCode = '') => {
  return http.request({
    method: 'POST',
    url: '/app/oauth/h5/code',
    data: { phone: phone, code: code, loginCode: loginCode },
  });
};

/**
 * 注册
 * @param params form表单
 * @returns
 */
export const register = (params: object) => {
  return http.request({
    method: 'POST',
    url: '/app/oauth/register',
    data: params,
  });
};

/**
 * 忘记密码
 * @param form
 * @returns
 */
export const forgetPassword = (form: object) => {
  return http.request({
    method: 'POST',
    url: '/app/oauth/forget',
    data: form,
  });
};

/**
 * 发送手机验证码
 * @param phone 手机号
 * @param action 行为操作
 * @returns
 */
export const sendSmsCaptcha = (phone: string, action: string) => {
  return http.request({
    method: 'POST',
    url: '/app/oauth/send_captcha',
    data: { key: 'MaTi', phone: phone, action: action },
  });
};

export const blank = () => {
  return http.request({
    method: 'GET',
    url: '/app/jwt/auth',
  });
};
